package com.artisan.provider.service.impl;

import com.artisan.provider.domain.ZgUser;
import com.artisan.provider.domain.ZgUserJurisdiction;
import com.artisan.provider.jsoup.po.ZgUserPoVos;
import com.artisan.provider.mapper.ZgUserJurisdictionMapper;
import com.artisan.provider.mapper.ZgUserMapper;
import com.artisan.provider.service.ZgUserService;
import com.artisan.provider.vo.UserCountListVo;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ZgUserServiceImpl implements ZgUserService {

    @Autowired
    ZgUserMapper zgUserMapper;

    @Autowired
    ZgUserJurisdictionMapper zgUserJurisdictionMapper;

    @Override
    public List<ZgUser> userFindAll(int page, int limit, ZgUser zgUser) {
        if(page > 0 && limit > 0){
            PageHelper.startPage(page,limit);
        }
        return zgUserMapper.selectUserList(zgUser);
    }

    @Override
    public int userAddUserInfo(ZgUser zgUser) {

        int i = 0;

        try {
            return zgUserMapper.insertSelective(zgUser);
        }catch (Exception e){
            return i;
        }

    }

    @Override
    public List<ZgUser> userFindAllList(ZgUser zgUser) {
        return zgUserMapper.selectAll();
    }

    @Override
    public List<ZgUser> zgUserListFindAll(ZgUser zgUser, int page, int limit) {
        if(page > 0 && limit > 0){
            PageHelper.startPage(page,limit);
        }
        return zgUserMapper.selectAll();
    }

    @Override
    public ZgUser userGetId(int id) {
        return zgUserMapper.userGetId(id);
    }

    @Override
    public List<ZgUser> userInfoFindList() {
        return null;
    }

    @Override
    public int userUpdate(ZgUser zgUser) {
        return zgUserMapper.updateByPrimaryKeySelective(zgUser);
    }

    /**
     * 逻辑删除
     * @param id
     * @return
     */
    @Override
    public int userDeleteId(int id) {
        return zgUserMapper.deleteUserFlag(id);
    }

    @Override
    public int userInputAdd(ZgUser zgUser) {
        return zgUserMapper.insertSelective(zgUser);
    }

    /**
     * 用户区域统计分析
     * @return
     */
    @Override
    public UserCountListVo userAddCountList() {
        UserCountListVo userCountListVo = new UserCountListVo();
        List<ZgUserPoVos> zgUserPoVos =  zgUserMapper.userAddCountList();
        List<String> stringList = zgUserMapper.userCountNameList();
        userCountListVo.setZgUsers(zgUserPoVos);
        userCountListVo.setZgNames(stringList);
        return userCountListVo;
    }

    @Override
    public ZgUserJurisdiction userLoginCurrentUser(ZgUser zgUser) {
        //校验权限用户
        return zgUserJurisdictionMapper.userInfoFind(zgUser);
    }

}
